/*
 * Copyright (C) 2012, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.controller;

import java.util.ArrayList;
import java.util.List;
import xowl.gmi.environment.UIAction;

/**
 *
 * @author Laurent WOUTERS
 */
public class DiagramUIAction extends UIAction {
    private List<UIAction> inners;
    private xowl.gmi.environment.DiagramController diagram;
    
    public void addInner(UIAction inner) { inners.add(inner); }
    public void setDiagram(xowl.gmi.environment.DiagramController diagram) { this.diagram  = diagram; }
    
    public DiagramUIAction(String description) {
        super(description);
        inners = new ArrayList<>();
    }
    
    @Override public void execute() {
        diagram.onModify();
        for (UIAction inner : inners)
            inner.execute();
    }
    @Override public void undo() {
        diagram.onModify();
        for (int i=inners.size()-1; i!=-1; i--)
            inners.get(i).undo();
    }
    @Override public void redo() {
        diagram.onModify();
        for (UIAction inner : inners)
            inner.redo();
    }
}
